{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Check if a String Is an Acronym of Words"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: isAcronym"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #判别首字母缩略词"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个字符串数组&nbsp;<code>words</code> 和一个字符串 <code>s</code> ，请你判断 <code>s</code> 是不是 <code>words</code> 的 <strong>首字母缩略词</strong> 。</p>\n",
    "\n",
    "<p>如果可以按顺序串联 <code>words</code> 中每个字符串的第一个字符形成字符串 <code>s</code> ，则认为 <code>s</code> 是 <code>words</code> 的首字母缩略词。例如，<code>\"ab\"</code> 可以由 <code>[\"apple\", \"banana\"]</code> 形成，但是无法从 <code>[\"bear\", \"aardvark\"]</code> 形成。</p>\n",
    "\n",
    "<p>如果 <code>s</code> 是 <code>words</code> 的首字母缩略词，返回 <code>true</code><em> </em>；否则，返回<em> </em><code>false</code> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong class=\"example\">示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>words = [\"alice\",\"bob\",\"charlie\"], s = \"abc\"\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>words 中 \"alice\"、\"bob\" 和 \"charlie\" 的第一个字符分别是 'a'、'b' 和 'c'。因此，s = \"abc\" 是首字母缩略词。 \n",
    "</pre>\n",
    "\n",
    "<p><strong class=\"example\">示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>words = [\"an\",\"apple\"], s = \"a\"\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>words 中 \"an\" 和 \"apple\" 的第一个字符分别是 'a' 和 'a'。\n",
    "串联这些字符形成的首字母缩略词是 \"aa\" 。\n",
    "因此，s = \"a\" 不是首字母缩略词。\n",
    "</pre>\n",
    "\n",
    "<p><strong class=\"example\">示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>words = [\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"], s = \"ngguoy\"\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>串联数组 words 中每个字符串的第一个字符，得到字符串 \"ngguoy\" 。\n",
    "因此，s = \"ngguoy\" 是首字母缩略词。 \n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= words.length &lt;= 100</code></li>\n",
    "\t<li><code>1 &lt;= words[i].length &lt;= 10</code></li>\n",
    "\t<li><code>1 &lt;= s.length &lt;= 100</code></li>\n",
    "\t<li><code>words[i]</code> 和 <code>s</code> 由小写英文字母组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [check-if-a-string-is-an-acronym-of-words](https://leetcode.cn/problems/check-if-a-string-is-an-acronym-of-words/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [check-if-a-string-is-an-acronym-of-words](https://leetcode.cn/problems/check-if-a-string-is-an-acronym-of-words/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[\"alice\",\"bob\",\"charlie\"]\\n\"abc\"', '[\"an\",\"apple\"]\\n\"a\"', '[\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"]\\n\"ngguoy\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isAcronym(self, words: List[str], s: str) -> bool:\n",
    "        acronym = ''\n",
    "        for word in words:\n",
    "            acronym+=word[0]\n",
    "        return acronym == s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isAcronym(self, words: List[str], s: str) -> bool:\n",
    "        if (len(words) != len(s)):\n",
    "            return False\n",
    "        for i in range(len(words)):\n",
    "            if words[i][0] != s[i]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isAcronym(self, words: List[str], s: str) -> bool:\n",
    "        return s == ''.join([w[0] for w in words])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\r\n",
    "\r\n",
    "\r\n",
    "class Solution:\r\n",
    "    def isAcronym(self, words: List[str], s: str) -> bool:\r\n",
    "        res = [word[0] for word in words]\r\n",
    "        return \"\".join(res) == s\r\n",
    "\r\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
